{include file="header/index" /}

<div class="newContentBox">
    <div class="fixedFather">
        <div class="fix">
            新增
            <!-- <span class="newNotice"><span class="newtext">*</span>为必填项</span> -->
            <div class="newFixBtnBox">
                <button type="button" class="newBtnDefault newBtnGray" onclick="returnBack(this)"><i
                        class="fa fa-mail-reply"></i>返回
                </button>
            </div>
        </div>
    </div>
    <form class="layui-form newListPart layui-none-top">
        <div class="layui-one-list">
            <div class="layui-form-item cover_layui_f_i">
                <label class="layui-form-label cover_layui_f_l"> 名单：</label>
                <div class="layui-input-block cover_layui_i_b">
                    <button type="button" class="newBtnDefault" id="uploadSIM">
                        <i class="fa fa-upload"></i>
                        导入人员名单
                    </button>
                    <div class="tishow" id="result"></div>
                    <div class="tishow"><i class="fa fa-info-circle"></i> 导入名单格式必须与模板一致 <a href="__IMG__/member_telpate.xlsx"  style="color: blue;">下载模板</a></div>

                </div>
            </div>
        </div>
        <div class="layui-one-list">
            <div class="layui-form-item cover_layui_f_i">
                <label class="layui-form-label cover_layui_f_l"> 类型：</label>
                <div class="layui-input-block cover_layui_i_b">
                    <select id="account_type" name="account_type" lay-verify="" lay-search>
                        <option value="1">扣款</option>
                        <option value="2">补贴</option>
                    </select>
                    <div class="tishow"><i class="fa fa-info-circle"></i> 将增加或者减少账户余额</div>
                </div>
            </div>
        </div>
        <div class="layui-one-list">
            <div class="layui-form-item cover_layui_f_i">
                <label class="layui-form-label cover_layui_f_l"> 积分：</label>
                <div class="layui-input-block cover_layui_i_b">
                    <input id="money" type="number" name="money" required lay-verify="required" autocomplete="off"
                           class="layui-input">
                    <div class="tishow"><i class="fa fa-info-circle"></i> 扣款积分或者补贴积分值,最多两位小数</div>
                </div>
            </div>
        </div>

        <div class="layui-one-list">
            <div class="layui-form-item cover_layui_f_i">
                <label class="layui-form-label cover_layui_f_l"> 说明：</label>
                <div class="layui-input-block cover_layui_i_b">
                    <textarea type="text" rows="5" name="note" id="note"
                              class="layui-textarea layui-input"></textarea>
                    <div class="tishow"><i class="fa fa-info-circle"></i> 说明</div>
                </div>
            </div>
        </div>


        <div class="layui-one-list">
            <div class="layui-form-item ">
                <div class="layui-input-block cover_layui_i_b">
                    <button class="layui-btn newBtnDefault newBtnPrimary" lay-submit lay-filter="formDemo">保存</button>
                    <button type="reset" class="layui-btn newBtnDefault">重置</button>
                </div>
            </div>
        </div>

    </form>
</div>
<script>
    var layer = layui.layer,
        element = layui.element,
        laydate = layui.laydate,
        laypage = layui.laypage,
        form = layui.form,
        upload = layui.upload,
        layedit = layui.layedit;
    var member = [];
    form.render();
    //提交表单
    var flag = false;
    form.on('submit(formDemo)', function (data) {

        if (flag) {
            return false;
        }
        flag = true;
        var request_data = {};
        request_data.member = member;
        request_data.account_type = $("#account_type").val();
        request_data.money = $("#money").val();
        request_data.note = $("#note").val();
        request_data = JSON.stringify(request_data);
        $.ajaxSetup({headers: {token: $.cookie('token'), company: $.cookie('company_id')}});
        $.post("{:config('api')}/Achievement/Dealer/add_meeting",request_data, function (e) {
            if (e.code == 1000) {
                top.layer.msg(e.message, {
                    icon: 1,
                    time: 2000
                }, function () {
                    top.layer.close();
                    //history.go(-1);
                    window.location.href = "{:url('meeting')}";
                });
            } else {
                top.layer.msg(e.message, {
                    icon: 0,
                    time: 2000
                });
            }
            flag = false;
        }, 'json');
        return false;
    });
    var uploadSIM = upload.render({
        elem: "#uploadSIM",
        url: "{:url('importMember')}",
        accept: 'file',
        exts:'xls|xlsx',
        field:'file',
        before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
            parent.layer.load(); //上传loading
        },
        done: function(res){
            parent.layer.closeAll();
            //上传完毕回调
            if(res.code == 1000) {
                parent.layer.msg(res.msg, {icon: 1,time: 2000},function(){
                    member = res.data;
                });
                $("#result").text('上传成功');

            }else{
                parent.layer.msg(res.msg, {icon: 2,time: 2000});
            }
        },
        error: function(err){
            //请求异常回调
            parent.layer.closeAll();
            parent.layer.msg('导入失败',{icon: 2,time: 2000});
        }
    })

</script>
